// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
// import ElementUI from 'element-ui';
// import 'element-ui/lib/theme-chalk/index.css';
// import { Button } from 'element-ui';
// import echarts from 'echarts'
import "./utils/element.js"
import App from './App'
import router from './router'
import VueQuillEditor from 'vue-quill-editor'

import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme


Vue.config.productionTip = false

// Vue.prototype.$echarts=echarts;
// Vue.use(ElementUI);
// Vue.component(Button.name, Button);
// Vue.use(Button)
/* eslint-disable no-new */
Vue.use(VueQuillEditor, /* { default global options } */)

// 全局钩子  登录权限判断
router.beforeEach((to,from,next)=>{
  // 设置title
  document.title =  `${to.meta.title}`;

  const role = localStorage.getItem("admin");
  // 字符串转对象   JSON.parse()   eval()  区别  
  const  val = eval("("+role+")")    //有风险  禁用
  // const val = JSON.parse(role);
  if (val !==null ) {
    const timeEnd = Date.now() - val.time;
    if (timeEnd > val.expire) {
      localStorage.removeItem("admin")
      next("/login")
      return null
    }

   } 

  //  没有登录 需要跳转到登录页
   if (!val && to.path !== '/login') {
    next("/login")
   } 
  //  模拟权限页面
   else if(to.meta.permission) {
     val.value == "admin" ? next() : next('/403')
   }else{
    // 判断浏览器是否支持富文本编辑器


   }


  next()
})




new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>'
})
